import { Contact } from "@/pond-contact/schema.contact";
import { User } from "@/stream-user/schema.user";
import { BIGINT_PG, INTEGER_PG, SMALLINT_PG, VARCHAR255_PG, VARCHAR50_PG, VARCHAR_PG } from "~/db.pg";

/** 基本信息介绍
 * @Ext 仅用于继承
 * @name 信息称呼
 * @desc 信息描述
 * @sequence 排序
 */
export type ExtIntro = {
  name: VARCHAR50_PG;
  desc: VARCHAR255_PG;
  content: VARCHAR255_PG;
  remark: VARCHAR255_PG;
  sequence: SMALLINT_PG;
};

/** 通用订单，必须包含交易记录和联系人
 * @Ext 仅用于继承
 * @contractSide 我方单位
 * @contractSideOp 对手单位
 * @contractBrief 简易条款
 * @amountTax 合计税额
 */
export type ExtOrder = ExtIntro & {
  contractSide: VARCHAR50_PG;
  contractSideOp: VARCHAR50_PG;
  contractTime: BIGINT_PG;
  contractBrief: VARCHAR_PG;

  code: VARCHAR50_PG;
  amount: INTEGER_PG;
  amountTax: INTEGER_PG;
};

/** 通用商品
 * @price 单价
 * @tax 税率，如13%
 */
export type ExtSkuTpl = ExtIntro & {
  // name: VARCHAR50_PG;
  // remark: VARCHAR255_PG;
  norm: VARCHAR255_PG;
  count: INTEGER_PG;
  unit: VARCHAR50_PG;

  price: INTEGER_PG;
  tax: SMALLINT_PG;
};

/** 创建人 */
export type Creatable = {
  refCreatorId: User["uuid32"];
  justCreator?: User;
};

/** 必须要有的交易要素
 * @refCreatorId 谁发起的交易
 * @refContactId 交易对象
 * @tradeId 交易标识
 */
export type Tradable = Creatable & {
  tradeId: VARCHAR255_PG;

  /** 交易时间 */
  tradeTime: BIGINT_PG;
  tradeYear: SMALLINT_PG;
  tradeMonth: SMALLINT_PG;

  /** 交易范围 */
  tradeScope: VARCHAR255_PG;

  refContactId: Contact["id"];
  justContact?: Contact;
};
